function [ F_best,max_PSO ] = PSO_AO2( p,c1,c2,L,NUM,K,T2,Hbar2,tau,rho,alpha,M,H1,e,F)
%UNTITLED2 此处显示有关此函数的摘要
%   此处显示详细说明
F_p=zeros(L,L,p);
value_p=zeros(1,p);
for i=1:p
    F_p(1:L,1:L,i)=diag(exp(rand(L,1)*(2*pi)*1i));
    value_p(:,i)=-100;
end
F_temp=F_p;
V=zeros(L,L,p);

F_best=F;
max_PSO=Sumrate_Detequi(K,L,M,T2,Hbar2,tau,rho,alpha,H1,F_best);

for j=1:NUM
    for i=1:p
       
        temp=Sumrate_Detequi(K,L,M,T2,Hbar2,tau,rho,alpha,H1,F_temp(:,:,i));
        
        if(temp>value_p(1,i))
            value_p(1,i)=temp;
            F_p(:,:,i)=F_temp(:,:,i);
        end
        if(value_p(1,i)>max_PSO)
            max_PSO=value_p(1,i);
            F_best=F_p(:,:,i);
        end
        V(:,:,i)=V(:,:,i)+c1*rand(L,L).*(F_p(:,:,i)-F_temp(:,:,i))+c2*rand(L,L).*(F_best-F_temp(:,:,i));
        F_temp(:,:,i)=F_temp(:,:,i)+V(:,:,i);
        for z=1:L
            F_temp(z,z,i)=F_temp(z,z,i)/abs(F_temp(z,z,i));
        end
    end
end
end

